<script setup lang="ts">
import Dialog from "@/view/Role/dialog.vue";
import { Delete, Edit, InfoFilled } from "@element-plus/icons-vue";
import useRole from "@/view/Role/utils/hook.tsx";
import { onMounted } from "vue";

const {
  roleList,
  dialog,
  getRoleList,
  addRole,
  EditRole,
  deleteRole
} = useRole()

onMounted(() => {
  getRoleList()
})
</script>

<template>
  <el-card class="card-category">
    <div class="card-category-list column">
      <div class="card-category-list-title row">
        <el-button type="primary" @click="addRole">添加角色</el-button>
      </div>
      <div class="card-category-list-table">
        <el-table
          border
          class="el-table-box"
          ref="multipleTableRef"
          :data="roleList"
          style="width: 100%"
        >
          <el-table-column type="index" label="#" align="center"/>
          <el-table-column prop="name" align="center" label="名称"/>
          <el-table-column align="center" label="控制" width="180">
            <template #default="{row}">
              <div class="operator-btn">
                <el-button type="primary" size="default" @click="EditRole(row)" :icon="Edit as any" circle/>
                <el-popconfirm
                  width="200"
                  @confirm="deleteRole(row._id)"
                  confirm-button-text="确定"
                  cancel-button-text="取消"
                  :icon="InfoFilled as any"
                  icon-color="#f36b6c"
                  title="您确定删除此角色吗?"
                >
                  <template #reference>
                    <el-button type="danger" size="default" :icon="Delete as any" circle/>
                  </template>
                </el-popconfirm>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <Dialog ref="dialog" @get="getRoleList"/>
  </el-card>
</template>

<style scoped lang="scss">
.card-category {
  padding: 0 50px;

  .card-category-list {

    .card-category-list-title {
      display: flex;
      justify-content: flex-end;
    }

    .card-category-list-table {
      margin-top: 20px;

      .el-table-box {
        height: calc(90vh - 140px);
      }
    }
  }
}
</style>
